<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-7-17
 * Time: 下午8:37
 */

namespace Actions;

use Data\Order_for_foods_DAO;
use Data\Order_form_DAO;
use Data\Food_DAO;
use Data\Retreat_order_form_DAO;
use Utils\SysUtils;

class RestaurantRetreatOrderForm extends BaseAction
{
    public function doAction() {
        parent::doAction();
        // 退单id
        $retreat_form_id = (int)$this->data[RETREAT_FORM_ID];
        // 退单记录
        $retreat_form_record = Retreat_order_form_DAO::getRecord($retreat_form_id);
        if (!$retreat_form_record) {
            return $this->SendErrMsg("错误,没有该退单信息");
        }
        // 订单id
        $order_form_id = $retreat_form_record->getORDER_FORM_ID();
        $order_form_record = Order_form_DAO::getRecord($order_form_id);
        if (!$order_form_record) {
            return $this->SendErrMsg("错误，没有此订单信息");
        }
        // 是否已付款
        $order_form_pay_status = $order_form_record->getPAY_STATUS();
        if(!$order_form_pay_status) {
            return $this->SendErrMsg("订单未付款，不能退单");
        }
        // 商家id
        $restaurant_id = $order_form_record->getRESTAURANT_ID();
        // 订单中商品信息
        $order_for_food_list = Order_for_foods_DAO::getListByOrderFormId($order_form_id);
        foreach ($order_for_food_list as $key=>$order_for_food_record) {
            $food_id = $order_for_food_record[FOOD_ID];
            $food_name = Food_DAO::getName($food_id);
            $order_for_food_list[$key][FOOD_NAME] = $food_name;
        }
        // 订单全部信息
        $order_info = array(ORDER_FORM_INFO=>$order_form_record->getArray(),ORDER_FOR_FOOD_INFO=>$order_for_food_list);
        $sendData = array(ORDER_INFO => $order_info);
        // 推送

        SysUtils::notifyTofFrontEnd($restaurant_id,$sendData,EVENT_RESTAURANT_RETREAT_ORDER_FORM);

        $this->ResponseDataToCurrentClient();
    }
}